
program zglHoD;
                  
uses
  SysUtils,
  CheckMem in 'CheckMem.pas',
  gm_engine in 'gm_engine.pas',
  XML in 'XML.pas',
  uDatFile in 'uDatFile.pas',
  gm_creature in 'gm_creature.pas',
  gm_generator in 'gm_generator.pas',
  gm_item in 'gm_item.pas',
  gm_map in 'gm_map.pas',
  gm_obj in 'gm_obj.pas',
  PathFind in 'PathFind.pas',
  gm_patterns in 'gm_patterns.pas',
  Utils in 'Utils.pas',
  Spell in 'Spell.pas',
  Resources in 'Resources.pas',
  CustomMap in 'CustomMap.pas',
  Stat in 'Stat.pas',
  Entity in 'Entity.pas',
  CustomCreature in 'CustomCreature.pas',
  Bar in 'Bar.pas',
  zglHeader in 'zglHeader.pas',
  Scenes in 'Scenes.pas',
  SceneMenu in 'SceneMenu.pas',
  SceneGame in 'SceneGame.pas',
  SceneInv in 'SceneInv.pas',
  SceneChar in 'SceneChar.pas',
  SceneFrame in 'SceneFrame.pas',
  SceneSkill in 'SceneSkill.pas',
  Hint in 'Hint.pas',
  Skill in 'Skill.pas',
  Belt in 'Belt.pas',
  IntBar in 'IntBar.pas';

procedure Init;
begin
  SceneManager := TScenes.Create;
  SetLength(CurrentScene, 0);

  SetLength(CurrentScene, 1);
  CurrentScene[scMenu] := TSceneMenu.Create;
  SetLength(CurrentScene, 2);
  CurrentScene[scGame] := TSceneGame.Create;
  SetLength(CurrentScene, 3);
  CurrentScene[scFrame] := TSceneFrame.Create;


  SceneManager.Scene := CurrentScene[scGame];
end;

procedure Render;
begin
  SceneManager.Render;
end;

procedure Update;
begin
  SceneManager.Update;
end;

procedure Quit;
var
  I: Byte;
begin
  for I := 0 to Length(CurrentScene) - 1 do FreeAndNil(CurrentScene[I]);
  SceneManager.Free;
  gm_patterns.Free;
end;

begin
  {$IF COMPILERVERSION >= 18}
  ReportMemoryLeaksOnShutdown := True;
  {$IFEND}
  if not zglLoad(libZenGL) then Exit;

  Randomize;

  timer_Add(@Update, 12);
  zgl_Reg(SYS_LOAD, @Init);
  zgl_Reg(SYS_DRAW, @Render);
  zgl_Reg(SYS_EXIT, @Quit);

  wnd_SetCaption('HoD');
  wnd_ShowCursor(True);

  zgl_Disable(APP_USE_LOG);
  zgl_Enable(CLIP_INVISIBLE);

  scr_SetOptions(ScreenWidth, ScreenHeight, 0, FullScr, VSync);

  zgl_Init;
end.

